﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PathHelper.cs" company="WordSteps.com">
//   All rights reserved
// </copyright>
// <summary>
//   Path Helper class
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace RapidDict.Infrastructure.Models
{
    using System;
    using System.IO;
    using System.Configuration;

    /// <summary>
    /// Path Helper class
    /// </summary>
    public class PathHelper
    {
        /// <summary>
        /// Gets IconPath.
        /// </summary>
        public static string IconPath
        {
            get
            {
                return GetFormatedPath("/Dictionary.ico");
            }
        }

        /// <summary>
        /// Gets Application Data Folder Path.
        /// </summary>
        public static string ApplicationDataFolderPath
        {
            get
            {
                string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                string localAppCompanyFolderPath = Path.Combine(localAppDataPath, GetDeployFolderName());

                if (!Directory.Exists(localAppCompanyFolderPath))
                {
                    Directory.CreateDirectory(localAppCompanyFolderPath);
                }

                return localAppCompanyFolderPath;
            }
        }

        /// <summary>
        /// Return full file path by its path inside project folder
        /// </summary>
        /// <param name="filePathInProject">
        /// The file path inside project structure.
        /// </param>
        /// <returns>
        /// full file path by its path inside project folder
        /// </returns>
        public static string GetFormatedPath(string filePathInProject)
        {
            string currentPath = Directory.GetCurrentDirectory();

            if (currentPath.EndsWith(@"\bin\Debug"))
            {
                currentPath = currentPath.Replace(@"\bin\Debug", String.Empty);
            }

            return String.Format(@"{0}\{1}", currentPath, filePathInProject);
        }

        private static string GetDeployFolderName()
        {
            return ConfigurationSettings.AppSettings["DeployFolderName"].ToString();
        }
    }
}